package main

import (
	"context"
	"fmt"
	"github.com/asim/go-micro/v3/client"
	"github.com/asim/go-micro/v3/metadata"
	"main/proto"
)

func main() {
	// 定义要调用的方法,注意格式
	serviceName := "go.micro.srv.user"
	serviceMethod := "User.GetUserInfo" // 方法名称带上user

	// 定义参数和返回
	params := &user.UserInfoRequest{
		UserName: "筱怪",
	}
	rsp := &user.UserInfoResponse{}

	// 请求和上下文
	req := client.NewRequest(
		serviceName,
		serviceMethod,
		params,
	)
	ctx := metadata.NewContext(
		context.Background(),
		map[string]string{
			"X-User-Id": "llqhz",
			"X-Form-Id": "micro-client",
		},
	)

	// 调用
	if err := client.Call(ctx, req, rsp); err != nil {
		panic(err)
	}
	fmt.Println("call rpc success: ", rsp)
}
